﻿<Window x:Class="AGMLite.Windows.EntityListWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:common="clr-namespace:AGMLite.Common"
        xmlns:local="clr-namespace:AGMLite.Windows"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        Title="{Binding Item.Name}" Height="600" Width="800" Icon="/AGMLite;component/agm.ico">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <local:ItemEntityNewConverter x:Key="ItemEntityNewConverter" />
                    <local:ItemEntityHealthConverter x:Key="ItemEntityHealthConverter" />
                    <Style TargetType="{x:Type Image}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UIElement}, AncestorLevel=1}, Path=IsEnabled}"  Value="False">
                                <Setter Property="Opacity"  Value="0.5" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <ToolBar>
            <Button Name="btnViewEntityDetail" Command="{Binding ViewEntityDetailCommand}"  CommandParameter="{Binding SelectedItem, ElementName=dataGridItemEntities}">
                <Image Source="/AGMLite;component/images/view.png" Height="20" Width="20" ToolTip="View Detail" />
            </Button>
            <Button Name="btnOpenEntityLink" Command="{Binding OpenEntityLinkCommand}"  CommandParameter="{Binding SelectedItem, ElementName=dataGridItemEntities}">
                <Image Source="/AGMLite;component/images/link.png" Height="20" Width="20" ToolTip="Open AGM Link" />
            </Button>
            <Separator VerticalAlignment="Stretch" />
            <ProgressBar Height="20" HorizontalAlignment="Stretch" Name="progressBarLoading" VerticalAlignment="Center" Width="500" Margin="2" IsIndeterminate="True" Visibility="Collapsed" />
        </ToolBar>
            <DataGrid Grid.Row="1" AutoGenerateColumns="False" 
                          HorizontalAlignment="Stretch" 
                          Name="dataGridItemEntities" 
                          VerticalAlignment="Stretch" 
                          SelectionMode="Single" 
                          ItemsSource="{Binding Item.LiteEntityCollection}"
                          CanUserAddRows="False"
                          CanUserDeleteRows="False" 
                          GridLinesVisibility="None" 
                          Margin="2"
                      RowHeaderWidth="0"
                          EnableRowVirtualization="True"
                          ScrollViewer.IsDeferredScrollingEnabled="True">
                    <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseDoubleClick">
                        <i:InvokeCommandAction Command="{Binding ViewEntityDetailCommand}"  CommandParameter="{Binding SelectedItem, ElementName=dataGridItemEntities}"  />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    <DataGrid.Columns>
                    <DataGridTemplateColumn Width="20" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Height="16" Width="16" Source="{Binding IsNew, Converter={StaticResource ItemEntityNewConverter}}" VerticalAlignment="Center" Margin="2">
                                            <Image.Style>
                                                <Style>
                                                    <Style.Triggers>
                                                        <EventTrigger RoutedEvent="Image.Loaded">
                                                            <BeginStoryboard>
                                                                <Storyboard>
                                                                    <DoubleAnimation Storyboard.TargetProperty="(Image.Opacity)" BeginTime="0:0:0" Duration="0:0:0.5" From="1.0" To="0.0" RepeatBehavior="Forever" AutoReverse="True"/>
                                                                </Storyboard>
                                                            </BeginStoryboard>
                                                        </EventTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Image.Style>
                                        </Image>
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="30" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Height="16" Width="16" Source="{Binding Health, Converter={StaticResource ItemEntityHealthConverter}}" ToolTip="{Binding HealthMessage}" VerticalAlignment="Center" Margin="2">
                                        </Image>
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="40" Header="ID" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Height="20" Margin="1">
                                        <TextBlock Margin="1"  VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Id}">
                                            <TextBlock.Style>
                                                <Style TargetType="TextBlock">
                                                    <Style.Setters>
                                                        <Setter Property= "FontWeight" Value="Bold"/>
                                                        <Setter Property= "FontSize" Value="11"/>
                                                    </Style.Setters>
                                                </Style>
                                            </TextBlock.Style>
                                        </TextBlock>
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="*" Header="Name" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Height="20" Margin="1">
                                        <TextBlock Margin="1"  VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Name}" ToolTip="{Binding Name}">
                                            <TextBlock.Style>
                                                <Style TargetType="TextBlock">
                                                    <Style.Setters>
                                                        <Setter Property= "FontWeight" Value="Bold"/>
                                                        <Setter Property= "FontSize" Value="11"/>
                                                        <Setter Property= "TextWrapping" Value="Wrap"/>
                                                    </Style.Setters>
                                                </Style>
                                            </TextBlock.Style>
                                        </TextBlock>
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>        
    </Grid>
</Window>
